package com.yhq.basic.thread;

import lombok.SneakyThrows;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 *
 * @author hqyin
 * @date 2023/11/29 11:33 AM
 */
public class  CreateThreadMethod {
    @SneakyThrows
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName()+" start");

        // 继承 Thread
        Thread1 thread1 = new Thread1() ;
        thread1.start();


        // impletement Runnable
        Thread2 thread2 = new Thread2();
        new Thread(thread2).start();

        //
        Thread3 thread3 = new Thread3();
        FutureTask<Integer> futureTask = new FutureTask<>(thread3);
        new Thread(futureTask).start();
        System.out.println("thread3 result:"+futureTask.get());



    }

    public static  class Thread1 extends Thread {
        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName()+" by extends Thread");
        }
    }

    public static class Thread2 implements Runnable {
        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName()+" by implements Runnable");
        }
    }

    public static class Thread3 implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            System.out.println(Thread.currentThread().getName()+" by implements Callable");
            return 1+1;
        }
    }
}


